package controller

import (
	"gin/common/lib"
	"gin/middleware"
	"gin/model/body"
	"gin/service/exerciseService"
	"gin/util/jwt"
	"gin/util/map_builder"
	"gin/util/request"
	"github.com/gin-gonic/gin"
)

type ExerciseController struct {
}

func ExerciseRegister(router lib.RegisterRouterGroup, needLoginRouter lib.RegisterRouterGroup) {
	exercise := ExerciseController{}
	needLoginRouter.POST("/exercise/add", exercise.add)
	needLoginRouter.POST("/exercise/update", exercise.update)
	needLoginRouter.POST("/exercise/del", exercise.del)
	needLoginRouter.POST("/exercise/list", exercise.list)
	needLoginRouter.POST("/exercise/myList", exercise.myList)
	needLoginRouter.POST("/exercise/getDetail", exercise.getDetail)
}

// @Summary 添加运动类型
func (*ExerciseController) add(c *gin.Context) {
	// 绑定参数
	var p body.ExerciseAddParam
	request.Bind(c, &p)

	p.Uid = jwt.GetUid(c, true)

	exerciseService.Add(p)

	middleware.Success(c)
}

// @Summary 修改运动类型
func (*ExerciseController) update(c *gin.Context) {
	var p body.UpdateExerciseParam
	request.Bind(c, &p)
	exerciseService.Update(p)
	middleware.Success(c)
}

// @Summary 删除运动类型
func (*ExerciseController) del(c *gin.Context) {
	var p body.IdParam
	request.Bind(c, &p)

	exerciseService.Del(p.Id)
	middleware.Success(c)
}

// @Summary 获取运动类型列表
func (*ExerciseController) list(c *gin.Context) {
	uid := jwt.GetUid(c)

	list := exerciseService.List(uid)
	middleware.Success(c, map_builder.BuilderMap("list", list))
}

// @Summary 获取运动类型列表
func (*ExerciseController) myList(c *gin.Context) {
	uid := jwt.GetUid(c)

	list := exerciseService.MyList(uid)
	middleware.Success(c, map_builder.BuilderMap("list", list))
}

// @Summary 获取运动类型详情
func (*ExerciseController) getDetail(c *gin.Context) {
	var p body.IdParam
	request.Bind(c, &p)

	info := exerciseService.Detail(p.Id)

	middleware.Success(c, map_builder.BuilderMap("info", info))
}
